
using Youz.Common.DBUtility;
using Youz.CreditRepay.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace Youz.CreditRepay.DAL
{
    /// <summary>
    /// Pay_PPayResults Data Class
    /// </summary>
    public partial class Pay_PPayResultsDAL : BaseDAL
    {
		private DbHelperSQL DbHelperSQL = new DbHelperSQL();
        public string TableName = "Pay_PPayResults";

        public Pay_PPayResultsDAL()
        {}

        #region  成员方法
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Pay_PPayResults model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("insert into [Pay_PPayResults](");
            strSql.Append("[MerchOrderId],[TradeCode],[Version],[MerchantId],[OrderId],[RetCode],[RetMsg],[Status],[Message],[CreatedOn],[ModifiedOn]");
            strSql.Append(") values (");
            strSql.Append("@MerchOrderId,@TradeCode,@Version,@MerchantId,@OrderId,@RetCode,@RetMsg,@Status,@Message,@CreatedOn,@ModifiedOn");
            strSql.Append(")");
			
            SqlParameter[] parameters = {                  
                    new SqlParameter("@MerchOrderId", model.MerchOrderId),
                    new SqlParameter("@TradeCode", model.TradeCode),
                    new SqlParameter("@Version", model.Version),
                    new SqlParameter("@MerchantId", model.MerchantId),
                    new SqlParameter("@OrderId", model.OrderId),
                    new SqlParameter("@RetCode", model.RetCode),
                    new SqlParameter("@RetMsg", model.RetMsg),
                    new SqlParameter("@Status", model.Status),
                    new SqlParameter("@Message", model.Message),
                    new SqlParameter("@CreatedOn", DateTime.Now),
                    new SqlParameter("@ModifiedOn", DateTime.Now)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Pay_PPayResults model)
        {

            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("update [Pay_PPayResults] set ");
            strSql.Append("[TradeCode]=@TradeCode,[Version]=@Version,[MerchantId]=@MerchantId,[OrderId]=@OrderId,[RetCode]=@RetCode,[RetMsg]=@RetMsg,[Status]=@Status,[Message]=@Message,[PayTime]=@PayTime,[SettleDate]=@SettleDate,[ModifiedOn]=@ModifiedOn");
            strSql.Append(" where [MerchOrderId]=@MerchOrderId");
			
            SqlParameter[] parameters = {                  
                    new SqlParameter("@MerchOrderId", model.MerchOrderId),
                    new SqlParameter("@TradeCode", model.TradeCode),
                    new SqlParameter("@Version", model.Version),
                    new SqlParameter("@MerchantId", model.MerchantId),
                    new SqlParameter("@OrderId", model.OrderId),
                    new SqlParameter("@RetCode", model.RetCode),
                    new SqlParameter("@RetMsg", model.RetMsg),
                    new SqlParameter("@Status", model.Status),
                    new SqlParameter("@Message", model.Message),
                    new SqlParameter("@PayTime", model.PayTime),
                    new SqlParameter("@SettleDate", model.SettleDate),
                    new SqlParameter("@ModifiedOn", DateTime.Now)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(String MerchOrderId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [Pay_PPayResults] ");
            strSql.Append(" where [MerchOrderId]=@MerchOrderId");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("@MerchOrderId", MerchOrderId)             
              
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Pay_PPayResults Get(String MerchOrderId)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select  top 1 * from [Pay_PPayResults] ");
            strSql.Append(" where [MerchOrderId]=@MerchOrderId");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("MerchOrderId", MerchOrderId)             
              
            };

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return Get(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

		/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Pay_PPayResults Get(DataRow row)
        {
            if (row == null) return null;

            Pay_PPayResults model = new Pay_PPayResults();
	
            
            if (row["ID"] != DBNull.Value)
            {
                model.ID = (Int32)row["ID"];
            }      
            
            if (row["MerchOrderId"] != DBNull.Value)
            {
                model.MerchOrderId = (String)row["MerchOrderId"];
            }      
            
            if (row["TradeCode"] != DBNull.Value)
            {
                model.TradeCode = (String)row["TradeCode"];
            }      
            
            if (row["Version"] != DBNull.Value)
            {
                model.Version = (String)row["Version"];
            }      
            
            if (row["MerchantId"] != DBNull.Value)
            {
                model.MerchantId = (String)row["MerchantId"];
            }      
            
            if (row["OrderId"] != DBNull.Value)
            {
                model.OrderId = (String)row["OrderId"];
            }      
            
            if (row["RetCode"] != DBNull.Value)
            {
                model.RetCode = (String)row["RetCode"];
            }      
            
            if (row["RetMsg"] != DBNull.Value)
            {
                model.RetMsg = (String)row["RetMsg"];
            }      
            
            if (row["Status"] != DBNull.Value)
            {
                model.Status = (Int32)row["Status"];
            }      
            
            if (row["Message"] != DBNull.Value)
            {
                model.Message = (String)row["Message"];
            }      
            
            if (row["PayTime"] != DBNull.Value)
            {
                model.PayTime = (DateTime)row["PayTime"];
            }      
            
            if (row["SettleDate"] != DBNull.Value)
            {
                model.SettleDate = (DateTime)row["SettleDate"];
            }      
            
            if (row["CreatedOn"] != DBNull.Value)
            {
                model.CreatedOn = (DateTime)row["CreatedOn"];
            }      
            
            if (row["ModifiedOn"] != DBNull.Value)
            {
                model.ModifiedOn = (DateTime)row["ModifiedOn"];
            }      
            

            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Gets(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select * from [Pay_PPayResults] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet Gets(int Top, string sqlWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" *  FROM [Pay_PPayResults] ");
			
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            if(filedOrder.Trim() != "")
            {
                strSql.Append(" order by " + filedOrder);
            }
			
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM [Pay_PPayResults] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable Gets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" SELECT * FROM [Pay_PPayResults]  ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }

            int count = 0;
            DataTable dt = DbHelperSQL.GetPager(pageindex, pagesize, "" + strSql + "", "order by ID desc ", out count, cmdParms);
            total = count;
            return dt;
        }
      #endregion  成员方法
    }
}


  